From 27ce68b74a0858447c8b86f63c4994f4666d9fef Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 6 Jun 2020 11:20:47 -0400 Subject: [PATCH] Add tests for select_callback --- testsuite/gtk/multiselection.c | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/testsuite/gtk/multiselection.c b/testsuite/gtk/multiselection.c index 2fd60aa1f5..f56387a878 100644 --- a/testsuite/gtk/multiselection.c +++ b/testsuite/gtk/multiselection.c @@ -438,6 +438,78 @@ test_readd (void) g_object_unref (selection); } +typedef struct { + guint start; + guint n; + gboolean in; +} SelectionData; + +static void +select_some (guint position, + guint *start, + guint *n, + gboolean *selected, + gpointer data) +{ + SelectionData *sdata = data; + guint i; + + for (i = 0; sdata[i].n != 0; i++) + { + if (sdata[i].start <= position && + position < sdata[i].start + sdata[i].n) + break; + } + + *start = sdata[i].start; + *n = sdata[i].n; + *selected = sdata[i].in; +} + +static void +test_callback (void) +{ + GtkSelectionModel *selection; + gboolean ret; + GListStore *store; + SelectionData data[] = { + { 0, 2, FALSE }, + { 2, 3, TRUE }, + { 5, 2, FALSE }, + { 6, 3, TRUE }, + { 9, 1, FALSE }, + { 0, 0, FALSE } + }; + + SelectionData more_data[] = { + { 0, 3, FALSE }, + { 3, 1, TRUE }, + { 4, 3, FALSE }, + { 7, 1, TRUE }, + { 0, 0, FALSE } + }; + + store = new_store (1, 10, 1); + + selection = new_model (store); + assert_model (selection, "1 2 3 4 5 6 7 8 9 10"); + assert_selection (selection, ""); + assert_selection_changes (selection, ""); + + ret = gtk_selection_model_select_callback (selection, select_some, data); + g_assert_true (ret); + assert_selection (selection, "3 4 5 7 8 9"); + assert_selection_changes (selection, "2:7"); + + ret = gtk_selection_model_unselect_callback (selection, select_some, more_data); + g_assert_true (ret); + assert_selection (selection, "3 5 7 9"); + assert_selection_changes (selection, "3:5"); + + g_object_unref (store); + g_object_unref (selection); +} + int main (int argc, char *argv[]) { @@ -456,6 +528,7 @@ main (int argc, char *argv[]) g_test_add_func ("/multiselection/selection", test_selection); g_test_add_func ("/multiselection/select-range", test_select_range); g_test_add_func ("/multiselection/readd", test_readd); + g_test_add_func ("/multiselection/callback", test_callback); return g_test_run (); } -- 2.30.2